/*
Copyright(c) 2008 Jari Kemppinen <jari@viddem.com>

This example was built upon the PureMVC Framework by Cliff Hall.
http://www.puremvc.org
This example uses the Java PureMVC Framework Version 0.2

Please contribute to the PureMVC community.

License
-------
Your reuse is governed by the Creative Commons Attribution 3.0 license.
 */

package org.lbroussal.client.view.components;

import org.lbroussal.client.view.SplashScreenMediator;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;

public class SplashScreen extends Composite {

    private Timer timer = null;

    private Image image = null;


    private SplashScreenMediator mediator;
    
    private HTML countDownLbl;
    
    private int counter = 4;
    
    private String countDownnText = "<font size='20' weight='bold'>counter</font>";

    public SplashScreen(SplashScreenMediator mediator) {
        this.mediator = mediator;

        image = new Image("http://howardscholz.files.wordpress.com/2007/06/puremvc2.png");
        
        VerticalPanel ui = new VerticalPanel();
        ui.setSize("100%", "100%");
        ui.setSpacing(2);   
        ui.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        ui.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        ui.add(new HTML("<b>When GWT is boosted by PureMVC :)</b>"));
        ui.add(new HTML("<b>Pure MVC was available for many languages :</b>"));
        ui.add(new HTML("<b>-.Net</b>"));
        ui.add(new HTML("<b>-AS3/Flex</b>"));
        ui.add(new HTML("<b>-PHP</b>"));
        ui.add(new HTML("<b>-Ruby</b>"));
        ui.add(new HTML("<b style='color:blue''>Now it comes reality for the wonderfull GWT  :)</b>"));
        countDownLbl = new HTML(countDownnText);
        ui.add(image);
        ui.add(new HTML("<b>Demo Loading ...</b>"));
        countDownLbl.setHTML(countDownnText.replaceFirst("counter", "5"));
        ui.add(countDownLbl);
        initWidget(ui);

        timer = new Timer() {

            @Override
            public void run() {
                if(counter == 0){
                    timer.cancel();
                    SplashScreen.this.mediator.GOTOMAIN();
                }else{
                    countDownLbl.setHTML(countDownnText.replaceFirst("counter", String.valueOf(counter)));
                    counter--;
                }
            }
            
        };
        timer.scheduleRepeating(1000);
    }
}
